]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
popupMenu: Use new convenience method for settings
authorRay Strode <rstrode@redhat.com>
Tue, 23 Aug 2011 14:14:55 +0000 (10:14 -0400)
committerRay Strode <rstrode@redhat.com>
Sun, 28 Aug 2011 16:16:04 +0000 (12:16 -0400)
All the system status menus in the panel offer a
menu item to jump to a relevant part of the
control-center.

This means each status icon has the same, or nearly the
same bit of code to:

- Add a new "action" menu item and listen for its activation.
- Hide the overview if it's showing when the menu item is activated
- Find the relevant control-center panel from its desktop file
- Launch the control-center to the relevant panel

This commit consolidates all those details in a new method,
addSettingsAction.  This refactoring reduces code duplication and
slight inconsistencies in the code resulting from that duplication.
It will also make it easier in subsequent commits to hide settings menu
items when the shell is used in the login screen.

https://bugzilla.gnome.org/show_bug.cgi?id=657082

js/ui/dateMenu.js
js/ui/popupMenu.js
js/ui/status/accessibility.js
js/ui/status/bluetooth.js
js/ui/status/keyboard.js
js/ui/status/network.js
js/ui/status/power.js
js/ui/status/volume.js

index edad21e65a616cbb96b257e82764072b29e65792..4a4b103230c3c08bcab0505b12a39dea718ac680 100644 (file)
@@ -84,13 +84,14 @@ DateMenuButton.prototype = {
                                }));
         vbox.add(this._calendar.actor);
 
-        item = new PopupMenu.PopupSeparatorMenuItem();
-        item.setColumnWidths(1);
-        vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false});
-        item = new PopupMenu.PopupMenuItem(_("Date and Time Settings"));
-        item.connect('activate', Lang.bind(this, this._onPreferencesActivate));
+        item = this.menu.addSettingsAction(_("Date and Time Settings"), 'gnome-datetime-panel.desktop');
+
+        let separator = new PopupMenu.PopupSeparatorMenuItem();
+        separator.setColumnWidths(1);
+        vbox.add(separator.actor, {y_align: St.Align.END, expand: true, y_fill: false});
+
         item.actor.can_focus = false;
-        vbox.add(item.actor);
+        item.actor.reparent(vbox);
 
         // Add vertical separator
 
@@ -201,13 +202,6 @@ DateMenuButton.prototype = {
         return false;
     },
 
-    _onPreferencesActivate: function() {
-        this.menu.close();
-        Main.overview.hide();
-        let app = Shell.AppSystem.get_default().lookup_setting('gnome-datetime-panel.desktop');
-        app.activate();
-    },
-
     _onOpenCalendarActivate: function() {
         this.menu.close();
         let calendarSettings = new Gio.Settings({ schema: 'org.gnome.desktop.default-applications.office.calendar' });
index 228fc76e2858000aa0e520b6b041064080448e0f..fc4956e25507bba14d3d2c30e9d54043269037a8 100644 (file)
@@ -803,11 +803,28 @@ PopupMenuBase.prototype = {
     },
 
     addAction: function(title, callback) {
-        var menuItem = new PopupMenuItem(title);
+        let menuItem = new PopupMenuItem(title);
         this.addMenuItem(menuItem);
         menuItem.connect('activate', Lang.bind(this, function (menuItem, event) {
             callback(event);
         }));
+
+        return menuItem;
+    },
+
+    addSettingsAction: function(title, desktopFile) {
+        let menuItem = this.addAction(title, function() {
+                           let app = Shell.AppSystem.get_default().lookup_setting(desktopFile);
+
+                           if (!app) {
+                               log('Settings panel for desktop file ' + desktopFile + ' could not be loaded!');
+                               return;
+                           }
+
+                           Main.overview.hide();
+                           app.activate();
+                       });
+        return menuItem;
     },
 
     /**
index 7792ed4ab1d9e9979a11db94f0803f32cb035441..dac4ef047cd1c897ee30c9aa71d6451b6da762ab 100644 (file)
@@ -88,11 +88,7 @@ ATIndicator.prototype = {
         this.menu.addMenuItem(mouseKeys);
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-        this.menu.addAction(_("Universal Access Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-universal-access-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop');
     },
 
     _buildItemExtended: function(string, initial_value, writable, on_set) {
index 2970b2c0861a3d9ad841a61c626d7e7f8e2896bc..77be89daf5662a49833e3030f3b71595ac94401e 100644 (file)
@@ -88,11 +88,7 @@ Indicator.prototype = {
         this._applet.connect('notify::show-full-menu', Lang.bind(this, this._updateFullMenu));
         this._updateFullMenu();
 
-        this.menu.addAction(_("Bluetooth Settings"), function() {
-            Main.overview.hide()
-            let app = Shell.AppSystem.get_default().lookup_setting('bluetooth-properties.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Bluetooth Settings"), 'bluetooth-properties.desktop');
 
         this._applet.connect('pincode-request', Lang.bind(this, this._pinRequest));
         this._applet.connect('confirm-request', Lang.bind(this, this._confirmRequest));
@@ -272,21 +268,15 @@ Indicator.prototype = {
 
         switch (device.type) {
         case GnomeBluetoothApplet.Type.KEYBOARD:
-            item.menu.addAction(_("Keyboard Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center keyboard');
-            });
+            item.menu.addSettingsAction(_("Keyboard Settings"), 'gnome-keyboard-panel.desktop');
             break;
         case GnomeBluetoothApplet.Type.MOUSE:
-            item.menu.addAction(_("Mouse Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center mouse');
-            });
+            item.menu.addSettingsAction(_("Mouse Settings"), 'gnome-mouse-panel.desktop');
             break;
         case GnomeBluetoothApplet.Type.HEADSET:
         case GnomeBluetoothApplet.Type.HEADPHONES:
         case GnomeBluetoothApplet.Type.OTHER_AUDIO:
-            item.menu.addAction(_("Sound Settings"), function() {
-                GLib.spawn_command_line_async('gnome-control-center sound');
-            });
+            item.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
             break;
         default:
             break;
index 7b425a43492edce25fa5b099c8593ec877f5cbb8..5a12df17aa3a5dd59415cf77dade168e86624977 100644 (file)
@@ -72,11 +72,7 @@ XKBIndicator.prototype = {
             Main.overview.hide();
             Util.spawn(['gkbd-keyboard-display', '-g', String(this._config.get_current_group() + 1)]);
         }));
-        this.menu.addAction(_("Region and Language Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-region-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Region and Language Settings"), 'gnome-region-panel.desktop');
     },
 
     _adjust_group_names: function(names) {
index 447efffcf932e7b2bb944177d64654c6438b8075..c4c42a53396db1407104845b9358a15c498fb128 100644 (file)
@@ -1609,12 +1609,7 @@ NMApplet.prototype = {
         this._devices.vpn.section.actor.hide();
         this.menu.addMenuItem(this._devices.vpn.section);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-
-        this.menu.addAction(_("Network Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-network-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
 
         this._activeConnections = [ ];
         this._connections = [ ];
index 9b88ac371ff7ee7d0c5332667b1d15e7ca26368f..baf0697eae3536a806dbdafd1b08e6ef478573a2 100644 (file)
@@ -77,13 +77,9 @@ Indicator.prototype = {
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this._otherDevicePosition = 2;
-        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
 
-        this.menu.addAction(_("Power Settings"),function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-power-panel.desktop');
-            app.activate();
-        });
+        this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
+        this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
 
         this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
         this._devicesChanged();
index 406ac66419b12f2c91dcc7802dddbe120021a7e8..76726a83cef78dbc84800073a600ccee38111b7e 100644 (file)
@@ -60,11 +60,7 @@ Indicator.prototype = {
         this.menu.addMenuItem(this._inputSlider);
 
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
-        this.menu.addAction(_("Sound Settings"), function() {
-            Main.overview.hide();
-            let app = Shell.AppSystem.get_default().lookup_setting('gnome-sound-panel.desktop');
-            app.activate();
-        });
+        this.menu.addSettingsAction(_("Sound Settings"), 'gnome-sound-panel.desktop');
 
         this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
         this._control.open();